/********************************************************************
	created:	2008/11/10
	created:	10:11:2008   23:20
	filename: 	h:\SimoneEngine\qianye\src\qylib\math\qyVector2.h
	author:		Xiong Jiayu
	copyright:  
	purpose:	
*********************************************************************/
#pragma once

#ifndef __QYVECTOR2_H__
#define __QYVECTOR2_H__

#include "qyMath.h"
#include <float.h>

/*
===========================================
struct Vector2
===========================================
*/
struct Vector2
{
public:
	float		x, y;
	
					Vector2();
	explicit		Vector2( const float x, const float y );
					Vector2( const Vector2 &v );
	
	void			Set( const float x, const float y );
	void			Zero( void );

	float			operator[]( int index ) const;
	float &			operator[]( int index );
	Vector2			operator-() const;
	float			operator*( const Vector2 &a ) const;
	Vector2			operator*( const float a ) const;
	Vector2			operator/( const float a ) const;
	Vector2			operator+( const Vector2 &a ) const;
	Vector2			operator-( const Vector2 &a ) const;
	Vector2 &		operator+=( const Vector2 &a );
	Vector2 &		operator-=( const Vector2 &a );
	Vector2 &		operator/=( const Vector2 &a );
	Vector2 &		operator/=( const float a );
	Vector2 &		operator*=( const float a );
	Vector2 &		operator=( const Vector2 &a );

	friend Vector2	operator*( const float a, const Vector2 b );

	bool			Compare( const Vector2 &a ) const;							// exact compare, no epsilon
	bool			Compare( const Vector2 &a, const float epsilon ) const;		// compare with epsilon
	bool			operator==(	const Vector2 &a ) const;						// exact compare, no epsilon
	bool			operator!=(	const Vector2 &a ) const;						// exact compare, no epsilon

	bool			IsZero( void ) const;

	float			Length( void ) const;
	float			LengthFast( void ) const;
	float			LengthSqr( void ) const;
	float			Normalize( void );			// returns length
	float			NormalizeFast( void );		// returns length
	Vector2 &		Truncate( float length );	// cap length
	void			Clamp( const Vector2 &min, const Vector2 &max );
	void			Snap( void );				// snap to closest integer value
	void			SnapInt( void );			// snap towards integer (floor)

	int				GetDimension( void ) const;

	const float *	ToFloatPtr( void ) const;
	float *			ToFloatPtr( void );
	const char *	ToString( int precision = 2 ) const;

	void			Lerp( const Vector2 &v1, const Vector2 &v2, const float l );

};

#include "qyVector2.inl"

//-----------------------------------------------------------------------
QY_INLINE Vector2::Vector2()
{
}

//-----------------------------------------------------------------------
QY_INLINE Vector2::Vector2( const float vX, const float vY )
: x( vX	)
, y( vY )
{}

//-----------------------------------------------------------------------
QY_INLINE Vector2::Vector2( const Vector2 &v )
: x( v.x )
, y( v.y )
{
}

#endif
